package com.dindang.checkline.mvp.greendao.controller;

import com.dindang.checkline.app.utils.DBUtils;
import com.dindang.checkline.app.utils.MyUtils;
import com.dindang.checkline.mvp.greendao.gen.ItemDetailEntityDao;
import com.dindang.checkline.mvp.model.entity.ItemDetailEntity;
import com.longxi.gamer_base.BaseAppConst;

import java.util.List;

/**
 * Created by cxw on & 2018/11/9
 */
public class CheckItemDetailController {

    private static ItemDetailEntityDao checkItemDetailDao  = DBUtils.getDaoSession().getItemDetailEntityDao();
    /**
     * 增加巡检项详情
     */
    public static long insertItemDetail(ItemDetailEntity item) {
        item.setUserid(BaseAppConst.accountInfo.getUserId()+"");
        return checkItemDetailDao.insertOrReplace(item);
    }

    /**
     * 删除巡检项详情
     */
    public static void deleteByid(ItemDetailEntity itemDetailEntity) {
        List<ItemDetailEntity> list = checkItemDetailDao.queryBuilder()
                .where(ItemDetailEntityDao.Properties.Userid.eq(BaseAppConst.accountInfo.getUserId()))
                .where(ItemDetailEntityDao.Properties.ItemId.eq(itemDetailEntity.itemId))
                .where(ItemDetailEntityDao.Properties.Pointid.eq(itemDetailEntity.pointid))
                .list();
        if(list!=null&&list.size()>0){
            checkItemDetailDao.delete(list.get(0));
        }
    }

    /**
     * 查巡检项详情列表根据巡检项id
     */
    public static List<ItemDetailEntity> selectNotSubmit()
    {
        //惰性加载
        List<ItemDetailEntity> list = checkItemDetailDao.queryBuilder()
                .where(ItemDetailEntityDao.Properties.Userid.eq(BaseAppConst.accountInfo.getUserId()))
                .list();
        return list;
    }

}
